package com.axjy.controller;

import java.time.LocalDate;
import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.axjy.pojo.Bingren;
import com.axjy.pojo.GhType;
import com.axjy.pojo.GuaHao;
import com.axjy.pojo.Keshi;
import com.axjy.service.BingrenService;
import com.axjy.service.GhTypeService;
import com.axjy.service.GuaHaoService;
import com.axjy.service.KeshiService;
import com.axjy.util.Pager;

@Controller
public class GuaHaoController {
	
	@Resource
	private GhTypeService ghTypeService;
	@Resource
	private GuaHaoService guaHaoService;
	@Resource
	private BingrenService bingrenService;
	@Resource
	private KeshiService keshiService;
	
	@RequestMapping("/searchGuaHao")
	public String guaHaoJsp() {
		return "qiantai/searchGuaHao";
	}
	
	@ResponseBody
	@RequestMapping("/searGuaHao")
	public Pager guaHao(Integer offset,Integer limit,String columnName,String columnValue) {
		return guaHaoService.pager(offset, limit, columnName, columnValue);
	}
	
	@RequestMapping("/guaHao")
	public String todayRegister(Model model) {
		LocalDate ghDate = LocalDate.now();
		model.addAttribute("ghDate",ghDate);
		return "qiantai/guaHao";
	}
	
	@ResponseBody
	@RequestMapping("/ghType")
	public List<GhType> ghType() {
		 return ghTypeService.list();
	}
	
	@ResponseBody
	@RequestMapping("/keshi")
	public List<Keshi> keshi(){
		return keshiService.list();
	}
	
	@ResponseBody
	@RequestMapping("/addGH")
	public String addGuaHao(Bingren bingren,GuaHao guahao,String brName,String brCard) {
		bingrenService.addBingren(bingren);
		int brId=bingrenService.searBingren(brName, brCard);
		guahao.setBrId(brId);
		int res=guaHaoService.addGuaHao(guahao);
		if(res>0) {
			return "success";
		}
		return "fail";
	}
}
